<template>
	<view class="setting-container">
	  <uni-card style="min-height: 260rpx;padding: 10rpx;">
		  <text style="font-size: 1.2em;">零件号：</text>
		  <input class="uni-input" placeholder="根据零件号搜索" v-model="search" style="width: 100;border-bottom: 1px #000 solid;margin-top: 30rpx;"/>
		  <button type="primary" size="mini" style="width: 100%;margin-top: 25rpx;" @click="doSearch">查询工单</button>
	  </uni-card>
	  <uni-card style="min-height: 500rpx;">
	  	<uni-table ref="table" :loading="loading" border stripe emptyText="暂无更多数据">
			<uni-tr>
				<uni-th width="80" align="center">零件号</uni-th>
				<uni-th width="40" align="center">工序</uni-th>
				<!-- <uni-th width="30">返工数量</uni-th> -->
				<uni-th width="30">报废数量</uni-th>
			</uni-tr>
			<uni-tr v-for="(item, index) in pageMix.records" :key="index" @tap.native="openInfo(item)">
				<uni-td align="center">{{ item.partNo }}</uni-td>
				<uni-td align="center">{{ item.processNo }}</uni-td>
				<!-- <uni-td>{{ item.rework }}</uni-td> -->
				<uni-td>{{ item.scrapNum }}</uni-td>
			</uni-tr>
		</uni-table>
		<view class="uni-pagination-box"><uni-pagination show-icon :page-size="pageMix.size" :current="pageMix.current" :total="pageMix.total" @change="pagination"/></view>
	  </uni-card>
	  <!-- 普通弹窗 -->
	  <uni-popup ref="popup">
		<uni-card title="任务信息" style="width: 90vw;">
			<uni-row>
				<uni-col :span="6" style="text-align: right;">零件号： </uni-col>
				<uni-col :span="18">{{infoData.partNo}}</uni-col>
				<uni-col :span="6" style="text-align: right;">流水号： </uni-col>
				<uni-col :span="18">{{infoData.productSerialNo}}</uni-col>
				<uni-col :span="6" style="text-align: right;">材料炉号： </uni-col>
				<uni-col :span="18">{{infoData.materialNo}}</uni-col>
				<uni-col :span="6" style="text-align: right;">上报时间： </uni-col>
				<uni-col :span="18">{{infoData.registrationTime}}</uni-col>
				<uni-col :span="6" style="text-align: right;">工序号： </uni-col>
				<uni-col :span="18">{{infoData.processNo}}</uni-col>
				<uni-col :span="6" style="text-align: right;">工序名称： </uni-col>
				<uni-col :span="18">{{infoData.processName}}</uni-col>
				<uni-col :span="6" style="text-align: right;">上报工号： </uni-col>
				<uni-col :span="18">{{infoData.startBy}}</uni-col>
				<uni-col :span="6" style="text-align: right;">不良数量： </uni-col>
				<uni-col :span="18">{{infoData.unQuantity}}</uni-col>
			</uni-row>
			<div style="height: 40rpx;"></div>
			<uni-row class="demo-uni-row">
				<uni-forms ref="baseForm" label-position="top">
				<uni-col :span="24" style="padding: 5px;">
					<uni-forms-item label="报废数量">
						<uni-easyinput type="number" v-model="infoData.scrapNum"/>
					</uni-forms-item>
				</uni-col>
				</uni-forms>
			</uni-row>
			
			<uni-row>
				<uni-col :span="24" style="padding: 10rpx;">
					<button type="primary" size="mini" style="width: 100%;" @click="doScrap">判定报废</button>
				</uni-col>
			</uni-row>
			<uni-row>
				<uni-col :span="24" style="padding: 10rpx;">
					<button size="mini" style="width: 100%;" @click="closeInfo">取消</button>
				</uni-col>
			</uni-row>
		</uni-card>
	  </uni-popup>
	</view>
</template>

<script>
  const apis = require('@/api/wip/WipDefective.js');
  export default {
  	data() {
  		return {
  			pageMix : apis.PageMix,
  			search : null,
  			entityPut : apis.entityPut,
  			entityPo : apis.entityPo,
  			loading: false,
			infoData:{
				partNo:null,
			},
  		}
  	},
  	onLoad() {
		this.loadTable()
  	},
  	methods: {
		loadTable(){
			this.pageMix.queryEntity.processType="质检"
  		    apis.pageMix(this.pageMix).then(response => {
  		          if(response.code===200){
  		            this.pageMix=response.data;
  		            this.pageMix.current=parseInt(response.data.current)
  		            this.pageMix.size=parseInt(response.data.size)
  		            this.pageMix.total=parseInt(response.data.total)
  		          }
  		        })
  		        .catch(error => {
  		          console.error('发生错误：', error);
  		        });
  		  },
		  pagination(type){
			  this.pageMix.current = type.current
			  this.loadTable()
		  },
		  doSearch(){
			  this.pageMix.queryEntity.partNo = this.search
			  this.loadTable()
		  },
		  openInfo(data){
			  this.infoData=data
			  this.infoData.scrapNum=0
			  this.$refs.popup.open()
		  },
		  closeInfo(){
			this.$refs.popup.close()
		  },
		  updateInfo(){
			  apis.update(this.infoData)
				  .then(response => {
					if(response.code===200){
					  this.loadTable()
					  this.$refs.popup.close()
					}
				  })
				  .catch(error => {
					console.error('发生错误：', error);
				  });
		  },
			doScrap(){
			  apis.doScrap(this.infoData.id+"",this.infoData.scrapNum)
				  .then(response => {
					if(response.code===200){
					  this.loadTable()
					  this.$refs.popup.close()
					}
				  })
				  .catch(error => {
					console.error('发生错误：', error);
				  });
			},
			rework(){
		      apis.rework(this.infoData.id+"",this.infoData.rework)
		          .then(response => {
		            if(response.code===200){
		              this.loadTable()
		              this.$refs.popup.close()
		            }
		          })
		          .catch(error => {
		            console.error('发生错误：', error);
		          });
		    }
  	}
  }
</script>

<style>
	.grid-item-box {
	  flex: 1;
	  /* #ifndef APP-NVUE */
	  display: flex;
	  /* #endif */
	  flex-direction: column;
	  align-items: center;
	  justify-content: center;
	  padding: 15px 0;
	}
</style>